/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package attackDetection;

import attackDetection2.Packet;
import java.util.ArrayList;
import java.sql.*;

/**
 *
 * @author john
 */
public class Node implements Comparable{

    private int nodeId;
    private int nodeIP;
    private ArrayList packetList;
    /* The following variables are from earlier work */
    private int rreqcount;
    private int rrepcount;
    private double rreqrate;
    private double rreqsavg;
    private double rreqdelta;
    private double talkfactor;
    private int nomsg;
    private final double FLOODINTERVAL = 15.0;
    private final double GVALUE = 0.5;
    private final double HVALUE = 0.25;
    /* End Variables */


    /* Constructors */
    public Node(){
        nomsg = 0;
        talkfactor = 1;
    }

    public Node(int id){
        nodeId = id;
    }

    public Node(int id, int ip){
        nodeId = id;
        nodeIP = ip;
    }

    public Node(int id, int ip, Packet p) {
        nodeId = id;
        nodeIP = ip;
        this.addPacket(p);
    }

    public void addPacket(Packet p) {
        packetList.add(p);
    }

    public String printSequenceNumbers(){
        return "Node: [" + this.getNodeId() + "," + this.getNodeIP()+ "]";
    }

    /* The following methods are from earlier work */
    public int init(ResultSet res)
    {
        return 1;
    }

    public void calparameter(Node n)
    {
        setRreqrate((double) (getRreqcount() / getFLOODINTERVAL()));
        rreqdelta = rreqrate - n.getRreqsavg();
        rreqsavg = n.getRreqsavg() + (GVALUE * rreqdelta);
    }

    public boolean comparelocationwb(double scalard, double timediff)
    {
        return comparescalard(scalard,timediff);
    }

    public boolean comparescalard(double scalard, double timediff)
    {
        double deltatime; //Maximum time error, time error from time synchronization problem
        double stdv; //Maximum Velocity of node
        double deltad; //Maximum distance error
        double r; //Maximum transmission range // */

        double i; //Internal Variable

        deltatime = 1;
        stdv = 0.0194; //Std velocity @ 70 m/hr
        deltad = 5;
        r = 50;

        i = ((timediff + deltatime) * stdv) + deltad;

        return scalard <= r+2*i;
    }

   

    /**
     * @return the nodeId
     */
    public int getNodeId() {
        return nodeId;
    }

    /**
     * @param nodeId the nodeId to set
     */
    public void setNodeId(int nodeId) {
        this.nodeId = nodeId;
    }

    /**
     * @return the nodeIP
     */
    public int getNodeIP() {
        return nodeIP;
    }

    /**
     * @param nodeIP the nodeIP to set
     */
    public void setNodeIP(int nodeIP) {
        this.nodeIP = nodeIP;
    }

    /**
     * @return the packetList
     */
    public ArrayList getPacketList() {
        return packetList;
    }

    /**
     * @param packetList the packetList to set
     */
    public void setPacketList(ArrayList packetList) {
        this.packetList = packetList;
    }

    /**
     * @return the rreqcount
     */
    public int getRreqcount() {
        return rreqcount;
    }

    /**
     * @param rreqcount the rreqcount to set
     */
    public void setRreqcount(int rreqcount) {
        this.rreqcount = rreqcount;
    }

    /**
     * @return the rrepcount
     */
    public int getRrepcount() {
        return rrepcount;
    }

    /**
     * @param rrepcount the rrepcount to set
     */
    public void setRrepcount(int rrepcount) {
        this.rrepcount = rrepcount;
    }

    /**
     * @return the rreqrate
     */
    public double getRreqrate() {
        return rreqrate;
    }

    /**
     * @param rreqrate the rreqrate to set
     */
    public void setRreqrate(double rreqrate) {
        this.rreqrate = rreqrate;
    }

    /**
     * @return the rreqdelta
     */
    public double getRreqdelta() {
        return rreqdelta;
    }

    /**
     * @param rreqdelta the rreqdelta to set
     */
    public void setRreqdelta(double rreqdelta) {
        this.rreqdelta = rreqdelta;
    }

    /**
     * @return the talkfactor
     */
    public double getTalkfactor() {
        return talkfactor;
    }

    /**
     * @param talkfactor the talkfactor to set
     */
    public void setTalkfactor(double talkfactor) {
        this.talkfactor = talkfactor;
    }

    /**
     * @return the nomsg
     */
    public int getNomsg() {
        return nomsg;
    }

    /**
     * @param nomsg the nomsg to set
     */
    public void setNomsg(int nomsg) {
        this.nomsg = nomsg;
    }

    /**
     * @return the FLOODINTERVAL
     */
    public double getFLOODINTERVAL() {
        return FLOODINTERVAL;
    }

    /**
     * @return the rreqsavg
     */
    public double getRreqsavg() {
        return rreqsavg;
    }

    /**
     * @param rreqsavg the rreqsavg to set
     */
    public void setRreqsavg(double rreqsavg) {
        this.rreqsavg = rreqsavg;
    }

    /**
     * @return the GVALUE
     */
    public double getGVALUE() {
        return GVALUE;
    }

    /**
     * @return the HVALUE
     */
    public double getHVALUE() {
        return HVALUE;
    }

    public int compareTo(Object o) {
        return nodeId - ((Node)o).getNodeId();
    }
}
